//
//  HXFacutlyTCell.m
//  ZCooking
//
//  Created by 韩旭 on 16/9/3.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "HXFacutlyTCell.h"
#import "HX_Macro.h"
#import "HXFacutlyCCell.h"
#import "HXTopicsSmallModel.h"

@implementation HXFacutlyTCell
- (void)setTopics:(NSMutableArray *)topics {
    _topics = topics;
    [_collectionView reloadData];
}
- (void)setUp {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = 1;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.bounces = NO;
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.showsHorizontalScrollIndicator = NO;
    [self.contentView addSubview:_collectionView];
    [_collectionView registerNib:[UINib nibWithNibName:@"HXFacutlyCCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"topicsCell"];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _topics.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HXFacutlyCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"topicsCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    HXTopicsSmallModel *smallModel = self.topics[indexPath.row];
    [cell.topImage sd_setImageWithURL:[NSURL URLWithString:smallModel.image]];
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(self.collectionView.HX_width / 3.2, self.collectionView.HX_height);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    self.rows(indexPath.row);
}
- (void)layoutSubviews {
    [super layoutSubviews];
    self.collectionView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
}
@end
